GridLib Module

History

current version 1.9 -18th March 2025

version date comment
0.1 02/Nov/2007 Original code
0.2 30/Nov/2008 extract grid of specified date
0.3 10/Dec/2008 export grid to netcdf dataset
0.4 13/Dec/2008 Add support to read ESRI GRID
0.5 18/May/2009 Add support to grid_mapping (makes use of GeoLib)
0.6 03/Jul/2009 export to file (ESRI GRID)
0.7 07/Apr/2010 added GetDtGrid
0.8 19/May/2011 increased decimal digits in header of exported esri grid
0.9 17/Jun/2011 add support to read netcdf file from WRF
1.0 11/Mar/2012 added GetFirstDate and GetTimeSteps
1.1 17/Jun/2013 added support for grid with non regularly spaced coordinates in netcdf dataset
1.2 15/Dec/2016 GetXYSizesFromFile modified to detect x and y coordinates by units
1.3 18/Feb/2019 GetXYSizesFromFile modified to detect coordinate convention lat-lon or lon-lat
1.4 20/Apr/2021 ScanTimeStringAsString to parse reference time in netcdf dataset
1.5 11/Apr/2022 SyncTime to return lower bounding time step of a given datetime
1.6 06/Apr/2023 comments reformatted to adhere FORD documenter standard
1.7 08/Nov/2024 increased number of decimal places of header in exported ESRI ASCII grid
1.8 21/Jan/2025 Easting and Northing used to find x and y coordinate
1.9 18/Mar/2025 minor bug fixing in reading coordinate reference system in netcdf files

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Module Description:

set of fortran routines to manage input and output of grids. The module supports different file formats:
NetCDF raster layer CF 1.0 compliant (Climate and Forecast metadata standard) ESRI ASCII grid ESRI BINARY grid

The module introduces two new variable types: grid_real to store floating point data, and grid_integer to store integer data.

Spatial conventions in netCDF file:

       y
  yDim ^     N
       |
       |  W     E
       |
       |     S
     1 |---------> x
       1        xDim 

index conventions: GRID(x,y)

Spatial conventions used in GridLib:

       1        jdim
     1 |---------> j
       |     N
       |
       |  W     E
       |
       |     S
 idim  v
      i  

index conventions: GRID(i,j)
To initialize a new grid variable, either integer or float, you can:

read grid from NetCdf file passing the standard name:

   TYPE(grid_real) :: new_grid 
   CALL NewGrid (new_grid, NetCdfFileName, stdName='air_temperature') 

read grid from NetCdf file passing name of variable:

   TYPE(grid_real) :: new_grid 
   CALL NewGrid (new_grid, NetCdfFileName, variable = 'T2m') 

If NetCdf archive is multitemporal, that is contains more grids, one for each time, you can retrieve the grid for a given time:

   TYPE(grid_real) :: new_grid
    TYPE (DateTime) :: ncTime
    ncTime = '2007-03-05T11:00:00+00:00'
   CALL NewGrid (new_grid, NetCdfFileName, stdName='air_temperature', time = ncTime) 

Read grid from ESRI ASCII file:

    TYPE(grid_real) :: new_grid
     fileName = 'file.asc'
    CALL NewGrid (new_grid, fileName, ESRI_ASCII) 

Read grid from ESRI BINARY file:

    TYPE(grid_real) :: new_grid
     fileName = 'file'
    CALL NewGrid (new_grid, fileName, ESRI_BINARY) 

Initialize grid using an existing one as template. The new grid is initialized with value 0:

    TYPE(grid_real) :: template
     TYPE(grid_integer) :: new_Grid
    CALL NewGrid (newGrid, template) 

If you want assign an initial value different than 0:

    CALL NewGrid (new_Grid, template, 100) 

The initial value must be of the same type as values stored in grid

To export a grid to a file you can:

write the grid to a netcdf file as variable termed VariableName:

   TYPE(grid_real) :: grid 
      ... some statements that assign data to grid
   CALL ExportGrid (grid, NetCdfFileName, VariableName, 'add')  

If the netcdf file is multitemporal, you can add grid to already existing ones in file:

   TYPE(grid_real) :: grid
      ... some statements that assign data to grid
   CALL ExportGrid (grid, NetCdfFileName, VariableName, 'append') 

If NetCdfFileName does not exist, it is created.

Write the grid to ESRI ASCII or BINARY file:

    TYPE(grid_real) :: grid
      ... some statements that assign data to grid
    fileName = 'file.asc'
    CALL ExportGrid (grid, fileName, ESRI_ASCII)
    fileName = 'file' 
   CALL ExportGrid (grid, fileName, ESRI_BINARY) 

If a grid is no more used you can free memory:

   TYPE(grid_real) :: grid
      ... some statements that assign data to grid
   CALL GridDestroy (grid) 

References: NetCDF: http://www.unidata.ucar.edu/software/netcdf/ CF 1.0: http://cf-pcmdi.llnl.gov/ UDUNITS: http://www.unidata.ucar.edu/software/udunits/

Description: read a float grid from a ESRI ASCII file. Description: given filename of a multidimensional net-cdf file the GetDtGrid function returns the temporal resolution (seconds) assuming that it is regular If option checkRegular is true the function check that temporal resolution is regular



Variables

Type Visibility Attributes Name Initial
integer(kind=short), public, parameter :: ESRI_ASCII = 1
integer(kind=short), public, parameter :: ESRI_BINARY = 2
integer(kind=short), public, parameter :: NET_CDF = 3
integer(kind=short), private, parameter :: MISSING_DEF_INT = -9999
real(kind=float), private, parameter :: MISSING_DEF_REAL = -9999.9

Interfaces

public interface ExportGrid

  • private subroutine ExportGridFloatToNetCDF(grid, file, name, action)

    export grid into netcdf file. Two actions are possible:

    • add: add a non-record variable to a netCDF dataset. If file does not exist it is created new. The added variable must have the same dimensions of already present variables. If you try to add a variable already present in netCDF dataset an error is returned.
    • append: append more data to record variables along the unlimited dimension. If netCDF dataset is created new, dimensions and attributes are set, otherwise only new data are written. If current time is already present in netcdf dataset an error is returned

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: grid

    grid to be exported

    character(len=*), intent(in) :: file

    netcdf file to export to

    character(len=*), intent(in) :: name

    name of variable in netcdf

    character(len=*), intent(in) :: action

    add or append

  • public subroutine ExportGridIntegerToNetCDF(grid, file, name, action)

    export grid into netcdf file. Two actions are possible:

    • add: add a non-record variable to a netCDF dataset. If file does not exist it is created new. The added variable must have the same dimensions of already present variables. If you try to add a variable already present in netCDF dataset an error is returned.
    • append: append more data to record variables along the unlimited dimension. If netCDF dataset is created new, dimensions and attributes are set, otherwise only new data are written. If current time is already present in netcdf dataset an error is returned

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: grid

    grid to be exported

    character(len=*), intent(in) :: file

    netcdf file to export to

    character(len=*), intent(in) :: name

    name of variable in netcdf

    character(len=*), intent(in) :: action

    add or append

  • private subroutine ExportGridFloatToFile(layer, fileName, fileFormat)

    export grid_real to file. List of supported format:

    • ESRI_ASCII: ESRI ASCII GRID
    • ESRI_BINARY: ESRI BINARY GRID

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(in) :: layer
    character(len=*), intent(in) :: fileName
    integer(kind=short), intent(in) :: fileFormat
  • private subroutine ExportGridIntegerToFile(layer, fileName, fileFormat)

    export grid_integer to file. List of supported format:

    • ESRI_ASCII: ESRI ASCII GRID
    • ESRI_BINARY: ESRI BINARY GRID

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(in) :: layer
    character(len=*), intent(in) :: fileName
    integer(kind=short), intent(in) :: fileFormat

public interface GetGridMapping

  • public function GetGridMappingFloat(layer) result(grid_mapping)

    get grid mapping for a floating point grid

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(inout) :: layer

    Return Value type(CRS)

  • public function GetGridMappingInteger(layer) result(grid_mapping)

    get grid mapping for a floating point grid

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(inout) :: layer

    Return Value type(CRS)

public interface GetTimeSteps

  • private function GetTimeStepsFromNCid(ncId) result(steps)

    given ncId of a multidimensional net-cdf file the GetTimeStepsFromNCid function returns the number of time steps

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=short), intent(in) :: ncId

    NetCdf Id for the file

    Return Value integer(kind=short)

  • private function GetTimeStepsFromFile(filename) result(steps)

    given filename of a multidimensional net-cdf file the GetTimeStepsFromFile function returns the number of time steps

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: filename

    Return Value integer(kind=short)

public interface GridDestroy

  • private subroutine GridDestroyFloat(layer)

    deallocate float grid

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(inout) :: layer
  • private subroutine GridDestroyInteger(layer)

    deallocate integer grid

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(inout) :: layer

public interface NewGrid

  • private subroutine NewGridFloatFromFile(layer, fileName, fileFormat, variable, stdName, time)

    read a grid from a file. List of supported format: ESRI_ASCII: ESRI ASCII GRID ESRI_BINARY: ESRI BINARY GRID NET_CDF: NetCDF CF compliant

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(out) :: layer

    gridreal to return

    character(len=*), intent(in) :: fileName

    file to read

    integer(kind=short), intent(in) :: fileFormat

    format of the file to read

    character(len=*), intent(in), optional :: variable

    variable to read

    character(len=*), intent(in), optional :: stdName

    standard name of the variable to read

    type(DateTime), intent(in), optional :: time

    time of the grid to read

  • private subroutine NewGridIntegerFromFile(layer, fileName, fileFormat, variable, stdName, time)

    read a grid from a file.

    • List of supported format:
    • ESRI_ASCII: ESRI ASCII GRID
    • ESRI_BINARY: ESRI BINARY GRID

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(out) :: layer

    grid to be returned

    character(len=*), intent(in) :: fileName

    file to read

    integer(kind=short), intent(in) :: fileFormat

    format of the file to read

    character(len=*), intent(in), optional :: variable

    variable to read

    character(len=*), intent(in), optional :: stdName

    standard name of the variable to read

    type(DateTime), intent(in), optional :: time

    time of the grid to read

  • private subroutine NewGridFloatAsGridFloat(layer, grid, initial)

    create a new grid_real using an existing grid_real as template

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(out) :: layer

    grid to be returned

    type(grid_real), intent(in) :: grid
    real(kind=float), intent(in), optional :: initial
  • private subroutine NewGridFloatAsGridInteger(layer, grid, initial)

    create a new grid_real using an existing grid_integer as template

    Arguments

    Type IntentOptional Attributes Name
    type(grid_real), intent(out) :: layer

    gridreal to return

    type(grid_integer), intent(in) :: grid
    real(kind=float), intent(in), optional :: initial
  • private subroutine NewGridIntegerAsGridInteger(layer, grid, initial)

    create a new grid_integer using an existing grid_integer as template

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(out) :: layer

    grid to be returned

    type(grid_integer), intent(in) :: grid
    integer, intent(in), optional :: initial
  • private subroutine NewGridIntegerAsGridFloat(layer, grid, initial)

    create a new grid_integer using an existing grid_real as template

    Arguments

    Type IntentOptional Attributes Name
    type(grid_integer), intent(out) :: layer

    grid to be returned

    type(grid_real), intent(in) :: grid
    integer, intent(in), optional :: initial

public interface SetCurrentTime

  • private subroutine SetCurrentTimeFloat(time, layer)

    set the current time of a float grid

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time
    type(grid_real), intent(inout) :: layer
  • private subroutine SetCurrentTimeInteger(time, layer)

    set the current time of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time
    type(grid_integer), intent(inout) :: layer

public interface SetEsriPeString

  • private subroutine SetEsriPeStringFloat(string, layer)

    set the esri pe string of a float grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: string
    type(grid_real), intent(inout) :: layer
  • private subroutine SetEsriPeStringInteger(string, layer)

    set the esri pe string of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: string
    type(grid_integer), intent(inout) :: layer

public interface SetLongName

  • private subroutine SetLongNameFloat(name, layer)

    set the long name of a float grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: name
    type(grid_real), intent(inout) :: layer
  • private subroutine SetLongNameInteger(name, layer)

    set the long name of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: name
    type(grid_integer), intent(inout) :: layer

public interface SetReferenceTime

  • private subroutine SetReferenceTimeFloat(time, layer)

    set the reference time of a float grid

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time
    type(grid_real), intent(inout) :: layer
  • private subroutine SetReferenceTimeInteger(time, layer)

    set the reference time of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    type(DateTime), intent(in) :: time
    type(grid_integer), intent(inout) :: layer

public interface SetStandardName

  • private subroutine SetStandardNameFloat(name, layer)

    set the standard name of a float grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: name
    type(grid_real), intent(inout) :: layer
  • private subroutine SetStandardNameInteger(name, layer)

    set the standard name of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: name
    type(grid_integer), intent(inout) :: layer

public interface SetUnits

  • private subroutine SetUnitsFloat(units, layer)

    set the units of a float grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: units
    type(grid_real), intent(inout) :: layer
  • private subroutine SetUnitsInteger(units, layer)

    set the units of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: units
    type(grid_integer), intent(inout) :: layer

public interface SetVaryingMode

  • private subroutine SetVaryingModeFloat(varMod, layer)

    set the varying mode of a float grid Possible values:

    • linear: linear variation between two dates
    • sequence: new grid substitute the previous as frames in a movie

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: varMod
    type(grid_real), intent(inout) :: layer
  • private subroutine SetVaryingModeInteger(varMod, layer)

    set the varying mode of a integer grid

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: varMod
    type(grid_integer), intent(inout) :: layer

Derived Types

type, public ::  grid_integer

Components

Type Visibility Attributes Name Initial
integer(kind=short), public, ALLOCATABLE :: Iraster(:,:)

used to transform not regular grid to regular raster

integer(kind=short), public, ALLOCATABLE :: Jraster(:,:)

used to transform not regular grid to regular raster georeferencing informations

real(kind=float), public :: cellsize
type(DateTime), public :: current_time

current date and time of the grid in memory

character(len=1000), public :: esri_pe_string

used by ArcMap 9.2

character(len=300), public :: file_name

name of the file from which grid was read

type(CRS), public :: grid_mapping

Coordinate reference System

integer(kind=short), public :: idim

number of rows

integer(kind=short), public :: jdim

number of columns

character(len=300), public :: long_name

long descriptive name

integer(kind=long), public, ALLOCATABLE :: mat(:,:)

data contained in grid

type(DateTime), public :: next_time

time when next update is required

integer(kind=short), public :: nodata

scalar identifying missing value

type(DateTime), public :: reference_time

reference time from which calculate current

character(len=300), public :: standard_name

CF 1.0 compliant standard name

integer(kind=short), public :: time_index

position of grid in time dimension in netcdf file

character(len=7), public :: time_unit

define time unit. Accepted values are: seconds, second, sec, s minutes, minute, min hours, hour, hr, h days, day, d

character(len=30), public :: units

UDUNITS compliant measure units

integer(kind=long), public :: valid_max

maximum valid value

integer(kind=long), public :: valid_min

minimum valid value

character(len=300), public :: var_name

name of the variable

character(len=20), public :: varying_mode

mode to vary: steady, sequence, linear

real(kind=float), public :: xllcorner
real(kind=float), public :: yllcorner

type, public ::  grid_real

Components

Type Visibility Attributes Name Initial
integer(kind=short), public, ALLOCATABLE :: Iraster(:,:)

used to transform not regular grid to regular raster

integer(kind=short), public, ALLOCATABLE :: Jraster(:,:)

used to transform not regular grid to regular raster georeferencing informations

real(kind=float), public :: cellsize
type(DateTime), public :: current_time

current date and time of the grid in memory

character(len=1000), public :: esri_pe_string

used by ArcMap 9.2

character(len=300), public :: file_name

name of the file from which grid was read

type(CRS), public :: grid_mapping

Coordinate reference System

integer(kind=short), public :: idim

number of rows

integer(kind=short), public :: jdim

number of columns

character(len=300), public :: long_name

long descriptive name

real(kind=float), public, ALLOCATABLE :: mat(:,:)

data variable contained in grid

type(DateTime), public :: next_time

time when next update is required

real(kind=float), public :: nodata

scalar identifying missing value

type(DateTime), public :: reference_time

reference time from which calculate current

character(len=300), public :: standard_name

CF 1.0 compliant standard name

integer(kind=short), public :: time_index

position of grid in time dimension in netcdf file

character(len=7), public :: time_unit

define time unit. Accepted values are: seconds, second, sec, s minutes, minute, min hours, hour, hr, h days, day, d

character(len=30), public :: units

UDUNITS compliant measure units

real(kind=float), public :: valid_max

maximum valid value

real(kind=float), public :: valid_min

minimum valid value

character(len=300), public :: var_name

name of the variable

character(len=20), public :: varying_mode

mode to vary: sequence, linear

real(kind=float), public :: xllcorner
real(kind=float), public :: yllcorner

Functions

public function GetDtGrid(filename, checkRegular) result(dt)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
logical, intent(in), optional :: checkRegular

Return Value integer(kind=long)

public function GetFirstDate(filename) result(time)

given filename of a multidimensional net-cdf file the GetFirstDate function returns the date and time of first grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

Return Value type(DateTime)

public function GetGridMappingFloat(layer) result(grid_mapping)

get grid mapping for a floating point grid

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(inout) :: layer

Return Value type(CRS)

public function GetGridMappingInteger(layer) result(grid_mapping)

get grid mapping for a floating point grid

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(inout) :: layer

Return Value type(CRS)

public function TimeByIndex(ncId, refTime, timeUnit, index) result(time)

Description returns time given time index

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

type(DateTime), intent(in) :: refTime

reference time to calculate time index

character(len=*), intent(in) :: timeUnit
integer(kind=short), intent(in) :: index

time step

Return Value type(DateTime)

returned time

private function GetTimeStepsFromFile(filename) result(steps)

given filename of a multidimensional net-cdf file the GetTimeStepsFromFile function returns the number of time steps

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename

Return Value integer(kind=short)

private function GetTimeStepsFromNCid(ncId) result(steps)

given ncId of a multidimensional net-cdf file the GetTimeStepsFromNCid function returns the number of time steps

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

Return Value integer(kind=short)

private function NextTime(ncId, refTime, timeUnit, current) result(time)

Description returns the time of the next grid in netcdf dataset

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

type(DateTime), intent(in) :: refTime

reference time to calculate time index

character(len=*), intent(in) :: timeUnit
integer(kind=short), intent(in) :: current

current time step

Return Value type(DateTime)

returned time of the next grid

private function TimeIndex(ncId, refTime, timeUnit, time) result(index)

Calculate the index to extract the corresponding slice from netcdf file.

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

type(DateTime), intent(in) :: refTime

reference time to calculate time index

character(len=*) :: timeUnit
type(DateTime), intent(in) :: time

time to calculate index from reference time

Return Value integer(kind=short)


Subroutines

public subroutine ExportGridIntegerToNetCDF(grid, file, name, action)

export grid into netcdf file. Two actions are possible:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: grid

grid to be exported

character(len=*), intent(in) :: file

netcdf file to export to

character(len=*), intent(in) :: name

name of variable in netcdf

character(len=*), intent(in) :: action

add or append

public subroutine SyncTime(fileName, given, time)

Description returns lower bounding time step of a given datetime

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileName
type(DateTime), intent(in) :: given
type(DateTime), intent(out) :: time

returned time of the grid to sync to

public subroutine ncErrorHandler(errcode)

Handle errors from netcdf related operation

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: errcode

private subroutine ExportGridFloatToESRI_ASCII(layer, fileName)

export grid_real to a ESRI ASCII file.

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: layer
character(len=*), intent(in) :: fileName

private subroutine ExportGridFloatToESRI_BINARY(layer, fileName)

export grid_real to a ESRI BINARY file.

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: layer
character(len=*), intent(in) :: fileName

private subroutine ExportGridFloatToFile(layer, fileName, fileFormat)

export grid_real to file. List of supported format:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: layer
character(len=*), intent(in) :: fileName
integer(kind=short), intent(in) :: fileFormat

private subroutine ExportGridFloatToNetCDF(grid, file, name, action)

export grid into netcdf file. Two actions are possible:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(in) :: grid

grid to be exported

character(len=*), intent(in) :: file

netcdf file to export to

character(len=*), intent(in) :: name

name of variable in netcdf

character(len=*), intent(in) :: action

add or append

private subroutine ExportGridIntegerToESRI_ASCII(layer, fileName)

export grid_integer to a ESRI ASCII file.

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: layer
character(len=*), intent(in) :: fileName

private subroutine ExportGridIntegerToESRI_BINARY(layer, fileName)

export grid_integer to a ESRI BINARY file.

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: layer
character(len=*), intent(in) :: fileName

private subroutine ExportGridIntegerToFile(layer, fileName, fileFormat)

export grid_integer to file. List of supported format:

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(in) :: layer
character(len=*), intent(in) :: fileName
integer(kind=short), intent(in) :: fileFormat

private subroutine GetGeoreferenceFromNCdataSet(ncId, varId, cellsize, xll, yll, grid_mapping, Iraster, Jraster, point2raster)

read and calculate georeferencing informations from netCDF file.

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

integer(kind=short), intent(in) :: varId

variable Id

real(kind=float), intent(out) :: cellsize

cell resolution

real(kind=float), intent(out) :: xll

x coordinate of lower left corner of map

real(kind=float), intent(out) :: yll

y coordinate of lower left corner of map

type(CRS), intent(out) :: grid_mapping

coordinate reference system

integer(kind=short), intent(inout) :: Iraster(:,:)
integer(kind=short), intent(inout) :: Jraster(:,:)
logical, intent(in) :: point2raster

private subroutine GetXYSizesFromFile(ncId, x, y, idx, idy, shape, latlon)

extraxt the number of columns (x) and rows (y) from netCDF file.

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

integer(kind=short), intent(out) :: x

number of columns and rows

integer(kind=short), intent(out) :: y

number of columns and rows

integer(kind=short), intent(out), optional :: idx

id of x variable

integer(kind=short), intent(out), optional :: idy

id of y variable

character(len=*), intent(out) :: shape

ccordinate in vector or matrix

integer(kind=short), intent(out), optional :: latlon

coordinate order is lat-lon (1) or lon-lat (2)

private subroutine GridDestroyFloat(layer)

deallocate float grid

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(inout) :: layer

private subroutine GridDestroyInteger(layer)

deallocate integer grid

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(inout) :: layer

private subroutine NewGridFloatAsGridFloat(layer, grid, initial)

create a new grid_real using an existing grid_real as template

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(out) :: layer

grid to be returned

type(grid_real), intent(in) :: grid
real(kind=float), intent(in), optional :: initial

private subroutine NewGridFloatAsGridInteger(layer, grid, initial)

create a new grid_real using an existing grid_integer as template

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(out) :: layer

gridreal to return

type(grid_integer), intent(in) :: grid
real(kind=float), intent(in), optional :: initial

private subroutine NewGridFloatFromESRI_ASCII(fileName, layer)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileName

file to read

type(grid_real), intent(out) :: layer

returned grid float

private subroutine NewGridFloatFromESRI_BINARY(fileName, layer)

read a float grid from a ESRI BINARY file.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileName

file to read

type(grid_real), intent(out) :: layer

returned grid float

private subroutine NewGridFloatFromFile(layer, fileName, fileFormat, variable, stdName, time)

read a grid from a file. List of supported format: ESRI_ASCII: ESRI ASCII GRID ESRI_BINARY: ESRI BINARY GRID NET_CDF: NetCDF CF compliant

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(out) :: layer

gridreal to return

character(len=*), intent(in) :: fileName

file to read

integer(kind=short), intent(in) :: fileFormat

format of the file to read

character(len=*), intent(in), optional :: variable

variable to read

character(len=*), intent(in), optional :: stdName

standard name of the variable to read

type(DateTime), intent(in), optional :: time

time of the grid to read

private subroutine NewGridFloatFromNetCDF(layer, fileName, variable, stdName, time)

create a new raster_real reading data from NetCDF file The variable to read can be defined by its current name or the standard_name. The dimensions x and y of the variable is calculated searching from the dimensions of the couple of variables with 'standard_name' equal to 'projection_x_coordinate' and 'projection_y_coordinate' for projected reference systems or 'longitude' and 'latitude' for geographic reference systems or 'grid_longitude' and 'grid_latitude' for rotated pole systems If a comprehensible reference systems is not found a geodetic reference system is supposed. Once the variable is retrieved, offset and scale factor are applied and a check on minimum and maximum valid value is performed.

Arguments

Type IntentOptional Attributes Name
type(grid_real), intent(out) :: layer

gridreal to return

character(len=*), intent(in) :: fileName

NetCDF file to be read

character(len=*), intent(in), optional :: variable

variable to read

character(len=*), intent(in), optional :: stdName

standard name of the variable to read

type(DateTime), intent(in), optional :: time

time of the grid to read

private subroutine NewGridIntegerAsGridFloat(layer, grid, initial)

create a new grid_integer using an existing grid_real as template

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(out) :: layer

grid to be returned

type(grid_real), intent(in) :: grid
integer, intent(in), optional :: initial

private subroutine NewGridIntegerAsGridInteger(layer, grid, initial)

create a new grid_integer using an existing grid_integer as template

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(out) :: layer

grid to be returned

type(grid_integer), intent(in) :: grid
integer, intent(in), optional :: initial

private subroutine NewGridIntegerFromESRI_ASCII(fileName, layer)

read a integer grid from a ESRI ASCII file.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileName

file to read

type(grid_integer), intent(out) :: layer

returned grid float

private subroutine NewGridIntegerFromESRI_BINARY(fileName, layer)

read a integer grid from a ESRI BINARY file.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileName

file to read

type(grid_integer), intent(out) :: layer

returned grid float

private subroutine NewGridIntegerFromFile(layer, fileName, fileFormat, variable, stdName, time)

read a grid from a file.

Read more…

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(out) :: layer

grid to be returned

character(len=*), intent(in) :: fileName

file to read

integer(kind=short), intent(in) :: fileFormat

format of the file to read

character(len=*), intent(in), optional :: variable

variable to read

character(len=*), intent(in), optional :: stdName

standard name of the variable to read

type(DateTime), intent(in), optional :: time

time of the grid to read

private subroutine NewGridIntegerFromNetCDF(layer, fileName, variable, stdName, time)

create a new grid_integer reading data from NetCDF file The variable to read can be defined by its current name or the standard_name. The dimensions x and j of the variable is calculated searching from the dimensions of the couple of variables with 'standard_name' equal to 'projection_x_coordinate' and 'projection_y_coordinate' for projected reference systems or 'longitude' and 'latitude' for geographic reference systems or 'grid_longitude' and 'grid_latitude' for rotated pole systems If a comprehensible reference systems is not found a geodetic reference system is supposed. Once the variable is retrieved, offset and scale factor are applied and a check on minimum and maximum valid value is performed.

Arguments

Type IntentOptional Attributes Name
type(grid_integer), intent(out) :: layer

gridreal to return

character(len=*), intent(in) :: fileName

NetCDF file to read

character(len=*), intent(in), optional :: variable

variable to read

character(len=*), intent(in), optional :: stdName

standard name of the variable to read

type(DateTime), intent(in), optional :: time

time of the grid to read

private subroutine ParseTime(ncId, ref_time, time_unit)

Parse units attribute of time variable Limits: string representing date and time must not contain blanks

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: ncId

NetCdf Id for the file

type(DateTime), intent(out) :: ref_time
character(len=7), intent(out) :: time_unit

private subroutine ScanTimeStringAsString(string, YYYY, MM, DD, hh, min, ss, tz)

scan a string to extract time information as character strings: year, month, day, hour, minute, second, timezone supported formats:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
character(len=*), intent(out) :: YYYY

year

character(len=*), intent(out) :: MM

month

character(len=*), intent(out) :: DD

day

character(len=*), intent(out) :: hh

hour

character(len=*), intent(out) :: min

minute

character(len=*), intent(out) :: ss

second

character(len=*), intent(out) :: tz

time zone

private subroutine SetCurrentTimeFloat(time, layer)

set the current time of a float grid

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
type(grid_real), intent(inout) :: layer

private subroutine SetCurrentTimeInteger(time, layer)

set the current time of a integer grid

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
type(grid_integer), intent(inout) :: layer

private subroutine SetEsriPeStringFloat(string, layer)

set the esri pe string of a float grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
type(grid_real), intent(inout) :: layer

private subroutine SetEsriPeStringInteger(string, layer)

set the esri pe string of a integer grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: string
type(grid_integer), intent(inout) :: layer

private subroutine SetLongNameFloat(name, layer)

set the long name of a float grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
type(grid_real), intent(inout) :: layer

private subroutine SetLongNameInteger(name, layer)

set the long name of a integer grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
type(grid_integer), intent(inout) :: layer

private subroutine SetReferenceTimeFloat(time, layer)

set the reference time of a float grid

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
type(grid_real), intent(inout) :: layer

private subroutine SetReferenceTimeInteger(time, layer)

set the reference time of a integer grid

Arguments

Type IntentOptional Attributes Name
type(DateTime), intent(in) :: time
type(grid_integer), intent(inout) :: layer

private subroutine SetStandardNameFloat(name, layer)

set the standard name of a float grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
type(grid_real), intent(inout) :: layer

private subroutine SetStandardNameInteger(name, layer)

set the standard name of a integer grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name
type(grid_integer), intent(inout) :: layer

private subroutine SetUnitsFloat(units, layer)

set the units of a float grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: units
type(grid_real), intent(inout) :: layer

private subroutine SetUnitsInteger(units, layer)

set the units of a integer grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: units
type(grid_integer), intent(inout) :: layer

private subroutine SetVaryingModeFloat(varMod, layer)

set the varying mode of a float grid Possible values:

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: varMod
type(grid_real), intent(inout) :: layer

private subroutine SetVaryingModeInteger(varMod, layer)

set the varying mode of a integer grid

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: varMod
type(grid_integer), intent(inout) :: layer

private subroutine SwapGridIntegerBack(matIn, matOut)

transport matrix from grid_integer to netcdf format

Arguments

Type IntentOptional Attributes Name
integer(kind=long), intent(in) :: matIn(:,:)
integer(kind=long), intent(out) :: matOut(:,:)

private subroutine SwapGridIntegerForward(matIn, matOut)

transport matrix from netcdf format to grid_integer

Arguments

Type IntentOptional Attributes Name
integer(kind=long), intent(in) :: matIn(:,:)
integer(kind=long), intent(out) :: matOut(:,:)

private subroutine SwapGridRealBack(matIn, matOut)

transport matrix from grid_real to netcdf format

Arguments

Type IntentOptional Attributes Name
real(kind=float), intent(in) :: matIn(:,:)
real(kind=float), intent(out) :: matOut(:,:)

private subroutine SwapGridRealForward(matIn, matOut, latlon)

transport matrix from netcdf format to grid_real

Arguments

Type IntentOptional Attributes Name
real(kind=float), intent(in) :: matIn(:,:)
real(kind=float), intent(out) :: matOut(:,:)
integer :: latlon